package daily.year2024.m11;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * No.187 重复的DNA序列
 *
 * @author wjs 2024/11/10
 */
public class d10 {
    class Solution {
        public List<String> findRepeatedDnaSequences(String s) {
            char[] chars = s.toCharArray();
            int n = chars.length;
            Set<String> set = new HashSet<>();
            Set<String> vals = new HashSet<>();
            int l = 0, r = 9;
            while(r < n) {
                StringBuilder sb = new StringBuilder();
                for(int i=l;i <= r;i++) {
                    sb.append(chars[i]);
                }
                String tmp = sb.toString();
                if(set.contains(tmp)) {
                    vals.add(tmp);
                }
                set.add(tmp);
                r++;
                l++;
            }
            return new ArrayList<>(vals);
        }
    }
}
